package test0109;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;

public class Test06 {
    // (6)统计字符串中每个字符出现的次数、map集合实现
    public static void main(String[] args) {
        String s = "sdfjkshdfjkkjwehrwer";
        Set<Character> treeSet = new TreeSet<>();
        for (int i = 0; i < s.length(); i++) {
            char s1 = s.charAt(i);
            treeSet.add(s1);
        }
        Map<Character, Integer> hashMap = new HashMap<>();
        for (Character c : treeSet) {
            hashMap.put(c, m1(s, c));
        }
        hashMap.forEach((x, y) -> {
            System.out.println(x + "\t" + y);
        });
    }

    public static Integer m1(String s, char c) {
        Integer count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == c) {
                count++;
            }
        }
        return count;
    }
}